<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>数组的reduce方法</title>
    </head>
    <body>
        <h1>数组的reduce方法</h1>
        <ol>
            <li>var arr=[1,2.3,0.78,3];</li>
            <li>var sum=arr.reduce(callFun,0);</li>
            <li>function callFun(previousValue,currentValue){</li>
            <li>return previousValue+Math.round(currentValue);</li>
            <li>}</li>
            <li>console.log(sum);//7</li>
        </ol>
        <script>
            var arr=[1,2.3,0.78,3];
            var sum=arr.reduce(callFun,0);
            function callFun(previousValue,currentValue){
                return previousValue+Math.round(currentValue);
            }
            console.log(sum);
        </script>
    </body>
</html>